package com.minhnvt1.game;

import android.view.MotionEvent;

import com.e3roid.E3Activity;
import com.e3roid.E3Engine;
import com.e3roid.E3Scene;
import com.e3roid.drawable.Shape;


public class E3droidActivity extends E3Activity {

	private final static int WIDTH = 320;
	private final static int HEIGHT = 480;
	private final static int BOX_SIZE = 50;
	
	private Shape shape1, shape2, shape3, shape4;
	
	@Override
	public E3Engine onLoadEngine() {
		E3Engine engine = new E3Engine(this, WIDTH, HEIGHT);
		engine.requestFullScreen();
		engine.requestPortrait();
		return engine;
	}

	@Override
	public void onLoadResources() {
		int centerX = getWidth() / 2;
		int centerY = getHeight() / 2;
		
		shape1 = new Shape(centerX, centerY, BOX_SIZE, BOX_SIZE);
        shape2 = new Shape(centerX-BOX_SIZE, centerY-BOX_SIZE, BOX_SIZE, BOX_SIZE);
        shape3 = new Shape(centerX-BOX_SIZE, centerY, BOX_SIZE, BOX_SIZE);
        shape4 = new Shape(centerX, centerY-BOX_SIZE, BOX_SIZE, BOX_SIZE); 
	}

	@Override
	public E3Scene onLoadScene() {
		E3Scene scene = new E3Scene();
		scene.addEventListener(this);
		
		
		shape1.setColor(1, 0, 0, 1);
        shape2.setColor(0, 1, 0, 1);
        shape3.setColor(0, 0, 1, 1);
        shape4.setColor(1, 1, 0, 1); 
        
        scene.getTopLayer().add(shape1);
        scene.getTopLayer().add(shape2);
        scene.getTopLayer().add(shape3);
        scene.getTopLayer().add(shape4);
        
		return scene;
	}
	@Override
    public boolean onSceneTouchEvent(E3Scene scene, MotionEvent motionEvent) {
        // shape1(red box) rotates and scales when touchEvent ACTION_DOWN occurs.
        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
            //Thực hiện xoay hình shape1 và phóng to khi bạn chạm vào màn hình
            shape1.rotate(shape1.getAngle() + 20.0f, BOX_SIZE/2, BOX_SIZE/2);
            shape1.scale(shape1.getScaleX() + 0.2f, shape1.getScaleY() + 0.2f, BOX_SIZE / 2, BOX_SIZE / 2);
        }
        return false;
    } 
}